{% extends "base.html" %}
{% comment 'header' %}
# This file is part of opentaps Smart Energy Applications Suite (SEAS).

# opentaps Smart Energy Applications Suite (SEAS) is free software:
# you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# opentaps Smart Energy Applications Suite (SEAS) is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public License
# along with opentaps Smart Energy Applications Suite (SEAS).
# If not, see <https://www.gnu.org/licenses/>.
{% endcomment %}

{% load django_tables2 %}
{% load static i18n %}
{% block title %}Transaction: {{ object.financial_transaction_id }}{% endblock %}

{% block content %}
<div class="container">

  {% include "core/_breadcrumbs.html" %}

  <div class="card mb-3">
    <div class="card-body">
    {% block inner_content %}
      <h2>Transaction {{ object.financial_transaction_id }}</h2>

      <div class="mb-3">
        <div class="row">
          <div class="col mb-2">&nbsp;</div>
          <div class="col-md mb-2"><b>Status:</b> {{ object.status }}</div>
        </div>
        <div class="row">
          <div class="col mb-2">&nbsp;</div>
          <div class="col-md mb-2"><b>Date:</b> {{ object.transaction_datetime }}</div>
        </div>
        <div class="row">
          <div class="col-md mb-2"><b>From:</b> {{ object.from_party }}</div>
          <div class="col mb-2">&nbsp;</div>
        </div>
        <div class="row">
          <div class="col-md mb-2"><b>To:</b> {{ object.to_party }}</div>
          <div class="col mb-2"><b>Amount:</b> {{ object.uom.symbol }} {{ object.amount }}</div>
        </div>
        <div class="row">
          <div class="col-md mb-2 mt-4"><i>{{ object.transaction_type }} for billing period from {{ object.from_datetime }} thru {{ object.thru_datetime }}
        {% if object.meter %}
          using meter <a href="{{ object.meter.get_absolute_url }}">{{ object.meter }}</a>
          {% if object.meter and object.meter.site %}
            at site <a href="{{ object.meter.site.get_absolute_url }}">{{ object.meter.site }}</a>
          {% endif %}
        {% endif %}
           Created at {{ object.created_datetime }}{% if object.created_by_user %} by {{ object.created_by_user }}{% endif %} from {{ object.source }}</div></i>
          </div>
        </div>
      </div>

      <div class="form-group d-flex justify-content-around mt-4">
        <a href="{% url 'core:transaction_delete' object.financial_transaction_id %}" class="btn btn-danger col-5" role="button"><i class="fa fa-trash mr-2"></i> Delete</a>
        {% if object.can_edit %}
        <a href="{% url 'core:transaction_edit' object.financial_transaction_id %}" class="btn btn-primary col-5" role="button"><i class="fa fa-edit mr-2"></i> Edit</a>
        {% else %}
        <a href="#" class="btn btn-primary col-5 disabled" role="button" aria-disabled="true"><i class="fa fa-edit mr-2"></i> Edit</a>
        {% endif %}
      </div>
    {% endblock inner_content %}
    </div>
  </div>

  {% if file_upload_form %}
    {% include "core/_upload.html" with form_title='Upload File' link_form_title='Add Link' form=file_upload_form items=files %}
  {% endif %}

  {% if notes_form %}
    {% include "core/_notes.html" with form_title='Add Note' form=notes_form items=notes %}
  {% endif %}

  {% if object.financialtransactionhistory_set.exists %}
  <div class="card mb-3">
    <div class="card-body">
      <h3>History</h3>
      <div class="container notes-table ftable">
      {% for h in object.financialtransactionhistory_set.all %}
        <div scope="row" class="row ftable-row align-items-start justify-content-between">
          <div class="owner-and-comments col-8 col-lg-auto row order-lg-2 order-1 text-nowrap m-0">{{ h.created_by_user }} <span class="ml-2 text-muted">{{ h.as_of_datetime }}</span></div>
          <div class="comments col-12 col-lg-8 order-3 order-lg-1">
            {{ h.history|linebreaks }}
          </div>
        </div>
      {% endfor %}
      </div>
    </div>
  </div>
  {% endif %}

</div>
{% endblock content %}
